# oyCutWithJoint by Ozgur Yilmaz (c) 2009
# 
# v1.0.0
#
# Description :
# -------------
# It's a simple script that cuts the selected mesh with the selected joint
# to create low poly versions of the rigged object
# 
# version history :
# -----------------
# v1.0.0
# - initial version
# 
# TODO List :
# -----------
#
# ----------------------------------------------------------------------------

import maya.cmds as cmd

def cut():
    selList = cmd.ls(sl=True)
    joint = selList[0]
    mesh = selList[1]

    if ( cmd.nodeType(joint) == "transform" ):
        temp = joint
        joint = mesh
        mesh = temp

    print "joint : %s" % joint
    print "mesh  : %s" % mesh

    rotateOrderDic = {0:"xyz",1:"yzx",2:"zxy",3:"xzy",4:"yxz",5:"zyx"}

    cutDir = rotateOrderDic[ cmd.getAttr(joint+".rotateOrder")][1]

    locator = cmd.spaceLocator()
    cmd.parent(locator,joint,r=True)
    cmd.parent(locator,w=True,r=False)
    cmd.rotate(0,90,0,locator,os=True,r=True)

    center = cmd.xform(locator,q=True,ws=True,t=True)
    rot = cmd.xform(locator,q=True,ws=True,ro=True)
    exOff = [0.0,0.0,0.0]

    cmd.polyCut( mesh, ef=True, eo=exOff, pc=center, ro=rot , ch=1)
    newMeshes = cmd.polySeparate( mesh )

    cmd.delete(locator)